<?php

/**
 * Subclass for performing query and update operations on the 'challenge' table.
 *
 * 
 *
 * @package lib.model
 */ 
class ChallengePeer extends BaseChallengePeer
{
	public static function doSelectWithPlayers($c)	{
		$challenges = parent::doSelect($c) ;

		foreach ($challenges as $challenge) {
			$c = new Criteria() ;
			$c->add(PlayerPeer::ID, $challenge->getP1Id()) ;
			$p1 = PlayerPeer::doSelectOne($c) ;
			
			$challenge->setP1($p1) ;

			$c = new Criteria() ;
			$c->add(PlayerPeer::ID, $challenge->getP2Id()) ;
			$p2 = PlayerPeer::doSelectOne($c) ;
			
			$challenge->setP2($p2) ;
		}
		
		return $challenges ;
	}

	public static function doSelectOneWithPlayers($c)	{
		$challenge = parent::doSelectOne($c) ;
		
		if (!$challenge)	{
			return false ;
		}

		$c = new Criteria() ;
		$c->add(PlayerPeer::ID, $challenge->getP1Id()) ;
		$p1 = PlayerPeer::doSelectOne($c) ;
		
		$challenge->setP1($p1) ;

		$c = new Criteria() ;
		$c->add(PlayerPeer::ID, $challenge->getP2Id()) ;
		$p2 = PlayerPeer::doSelectOne($c) ;
			
		$challenge->setP2($p2) ;
		
		return $challenge ;
	}
}
